<?php
namespace App\Utils\Server;

/**
 * @微信一步登录配置
 * 特别注意：此方法存在特殊性，一般用于微信一步登录功能
 * 2022年4月14日
 * Author：panda
 * email：joeyoung0314@qq.com
 */
class WxResult{
    // 微信一步登录配置
    protected static $CookieKey = 'wx_login';//cookie 键名

    /**
     * 成功返回200
     * @param string $url
     * @param string $message
     * @param null $result
     * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
     */
    public static function response200(string $url,string $message = '',$result = null)
    {
        setcookie(self::$CookieKey,json_encode([
            'code'=>200,
            'message'=>$message,
            'result'=>$result
        ],JSON_UNESCAPED_UNICODE), time() + 86400, "/", "", false, false);
        return redirect($url);
    }

    /**
     * 失败返回201
     * @param string $url
     * @param string $message
     * @param null $result
     * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
     */
    public static function response201(string $url,string $message = '',$result = null)
    {
        setcookie(self::$CookieKey,json_encode([
            'code'=>201,
            'message'=>$message,
            'result'=>$result
        ],JSON_UNESCAPED_UNICODE), time() + 86400, "/", "", false, false);
        return redirect($url);
    }

    /**
     * 当前微信未做关联返回202
     * @param string $url
     * @param string $message
     * @param null $result
     * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
     */
    public static function response202(string $url,string $message = '当前微信未做关联',$result = null)
    {
        setcookie(self::$CookieKey,json_encode([
            'code'=>202,
            'message'=>$message,
            'result'=>$result
        ],JSON_UNESCAPED_UNICODE), time() + 86400, "/", "", false, false);
        return redirect($url);
    }
}